package com.prs.crm.job.impl;

import java.util.List;

import com.prs.crm.domain.cqunicom.PoplarOrder;
import com.prs.crm.job.SetColorOrderTask;
import com.prs.crm.service.cqunicom.OrderService;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2011-4-11 上午09:51:21
 * 简单说明
 */

public class SetColorOrderTaskImpl implements SetColorOrderTask {

	private  OrderService orderService;
	public OrderService getOrderService() {
		return orderService;
	}
	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}
	/**
	 * 颜色设置
	 */
	@Override
	public void bysetColorTask() {
	//价格颜色设置
		setPriceColor();
	//交易状态和价格
		setStatePrice();
	//交易状态和价格的其他差异
		setStatePriceBlue();
		
	}

	//价格颜色
	public void setPriceColor(){
	List<PoplarOrder>	 orderAllList=this.getOrderService().getDispatchOrder();
	for(PoplarOrder order:orderAllList){
		if(order.getCompleDate()!=null){
			if(order.getMonitorOrder()!=null && order.getBusinessOrder()!=null){
				if(order.getMonitorOrder().getTradeAmount()!=order.getBusinessOrder().getDealPrice()){
					PoplarOrder  orderObject1=this.getOrderService().get(order.getId());
					orderObject1.setPriColor(2);
					this.getOrderService().saveOrupdate(orderObject1);
				}
			}
		}
	}
	}
	//交易状态和价格
	public void setStatePrice(){
		List<PoplarOrder>	 orderAllList=this.getOrderService().getDispatchOrder();
		for(PoplarOrder order:orderAllList){
			if(order.getCompleDate()!=null){
				if(order.getMonitorOrder()!=null && order.getBusinessOrder()!=null){
					if("成功回访".equals(order.getMonitorOrder().getVisitState()) && "未成交".equals(order.getBusinessOrder().getTransationSatet()) && order.getMonitorOrder().getTradeAmount()!=null){
						PoplarOrder  orderObject1=this.getOrderService().get(order.getId());
						orderObject1.setPriColor(2);
						orderObject1.setTredeSatets(2);
						this.getOrderService().saveOrupdate(orderObject1);
					}
					
				}
			}
		}
	}
	//交易状态和价格
	public void setStatePriceBlue(){
		List<PoplarOrder>	 orderAllList=this.getOrderService().getDispatchOrder();
		for(PoplarOrder order:orderAllList){
			if(order.getCompleDate()!=null){
				if(order.getMonitorOrder()!=null && order.getBusinessOrder()!=null){
					String bstate=order.getBusinessOrder().getTransationSatet();
					String mstate=order.getMonitorOrder().getVisitState();
					if(("未回访".equals(mstate)||"未回访".equals(mstate)) && ("无效".equals(bstate)||( "未成交".equals(bstate)&& order.getBusinessOrder().getDealPrice()==0))){
						PoplarOrder  orderObject1=this.getOrderService().get(order.getId());
						orderObject1.setPriColor(3);
						orderObject1.setTredeSatets(3);
						this.getOrderService().saveOrupdate(orderObject1);
					}
					
				}
			}
		}
	}
}
